package com.qigao.mall.web.controller;

import com.qigao.mall.api.IntentCustomerService;
import com.qigao.mall.commons.dto.IntentCustomerApplyDto;
import com.qigao.mall.commons.enums.Result;
import com.qigao.mall.commons.enums.ResultCode;
import com.qigao.mall.commons.exceptions.BusinessException;
import com.qigao.mall.web.utils.ValidatorUtil;
import com.qigao.mall.web.vo.app.IntentCustomerApplyVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author luiz
 * @Title: com.qigao.mall.web.controller.app.merchant
 * @ProjectName three-mall
 * @date 2020-04-2020/4/22 17:48
 * @Description:意向客户申请
 */
@RestController
@RequestMapping("/common/instentCustomer/")
@Api(tags = "意向客户")
public class IntentCustomerController {
    private static Logger logger= LoggerFactory.getLogger(IntentCustomerController.class);
    @Resource
    IntentCustomerService intentCustomerService;

    //1.意向客户申请
    @PostMapping("/apply")
    @ApiOperation(value = "意向客户申请", notes = "意向客户申请")
    public Result<String> apply(@RequestBody IntentCustomerApplyVo intentCustomerApplyVo, HttpServletRequest request){
        try{
            //参数校验
            ValidatorUtil.validateEntity(intentCustomerApplyVo,IntentCustomerApplyVo.class);
            IntentCustomerApplyDto intentCustomerApplyDto=new IntentCustomerApplyDto();
            BeanUtils.copyProperties(intentCustomerApplyVo,intentCustomerApplyDto);
            intentCustomerService.create(intentCustomerApplyDto);
            return Result.newSuccess();
        }catch (BusinessException be){
            logger.error("[意向客户申请]发生业务异常:{}",be);
            return Result.newError(be.getCode(),be.getMsg());
        }catch (Exception e){
            logger.error("[意向客户申请]发生异常:{}",e);
            return Result.newError(ResultCode.FAIL);
        }
    }

}
